package com.sailing.lianxi.io.nio;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;

public class FileVisitorTest {

	public static void t1() throws IOException{
		Files.walkFileTree(Paths.get("."),new SimpleFileVisitor<Path>(){

			//访问文件是触发
			@Override
			public FileVisitResult visitFile(Path file,
					BasicFileAttributes attrs) throws IOException {
				// TODO Auto-generated method stub
				System.out.println("正在访问===="+file);
				
				return FileVisitResult.CONTINUE;
			}
			//访问目录时触发
			@Override
			public FileVisitResult preVisitDirectory(Path dir,
					BasicFileAttributes attrs) throws IOException {
				System.out.println("访问目录==="+dir.getFileName());
				return super.preVisitDirectory(dir, attrs);
			}
			
			
		});
	}
	public static void main(String[] args) throws Exception {
		t1();
	}
}
